import { empPageSelecct } from '@/api/organize'
import { ref } from 'vue'

/**
 * 获取客服下拉选项
 */
export const useGetCustomerServiceOptions = () => {
  const getCustomerServiceOptionsLoading = ref(false)
  const getCustomerServiceOptionsParam = ref<OrderListAPIRequest.GetCustomerServiceOptionsParam>({
    limit: 100,
    page: 1,
    name: '',
  })
  const customerServiceOptions = ref<Array<OrderListAPIResponse.CustomerServiceOption>>([])

  const getCustomerServiceOptions = async () => {
    try {
      getCustomerServiceOptionsLoading.value = true
      const res = await empPageSelecct(getCustomerServiceOptionsParam.value)
      getCustomerServiceOptionsLoading.value = false
      if (res.data.code === 20000) {
        customerServiceOptions.value = res.data.data.rows
        return ''
      }
      return res.data.message
    } catch (error) {
      return '获取客服下拉选项失败，请稍后重试'
    }
  }

  return {
    customerServiceOptions,
    getCustomerServiceOptionsParam,
    getCustomerServiceOptionsLoading,
    getCustomerServiceOptions,
  }
}
